<template>
  <div>
    <el-radio-group v-if="!multiple" v-model="selectValue" :class="direction=='horizontal'?'':'d-grid'">
      <el-radio v-for="option in options" :key="'text_select_form_radio_' + option.value" :label="option.value" :disabled="disabled">{{ option.label }}</el-radio>
    </el-radio-group>
    <el-checkbox-group v-else v-model="selectValue" :class="direction=='horizontal'?'':'d-grid'">
      <el-checkbox v-for="option in options" :key="'text_select_form_checkbox_' + option.value" :label="option.value" :disabled="disabled">{{ option.label }}</el-checkbox>
    </el-checkbox-group>
  </div>
</template>

<script>
export default {
  name: 'TextSelect',
  props: {
    value: {
      type: String|Array,
      default: undefined
    },
    options: {
      type: Array,
      default: function () {
        return []
      },
      required: true
    },
    multiple: {
      type: Boolean,
      default: false
    },
    direction: {
      type: String,
      default: 'horizontal'
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    selectValue(val) {
      this.$emit('input', val)
    },
    value(val) {
      this.selectValue = val
    }
  },
  data() {
    return {
      selectValue: this.value
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .el-radio-button__inner,
.el-radio-group,
.el-checkbox-group {
  display: flex !important;
  flex-wrap: wrap;
}

.d-grid {
  display: grid !important;
  margin-top: 5px;
  margin-bottom: 5px;
  flex-wrap: wrap;

  label {
    margin-left: 5px;
    height: 35px;
    line-height: 35px;
  }
}

</style>
